﻿CREATE TABLE [lov].[Value] (
    [RowId]      UNIQUEIDENTIFIER NOT NULL,
    [FieldId]    INT              NOT NULL,
    [FieldValue] VARBINARY (MAX)  NOT NULL,
    CONSTRAINT [PK_Value] PRIMARY KEY CLUSTERED ([RowId] ASC, [FieldId] ASC),
    CONSTRAINT [FK_Value_Field] FOREIGN KEY ([FieldId]) REFERENCES [lov].[Field] ([Id]) ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT [FK_Value_Row] FOREIGN KEY ([RowId]) REFERENCES [lov].[Row] ([Id]) ON DELETE CASCADE ON UPDATE CASCADE
);






GO
CREATE UNIQUE NONCLUSTERED INDEX [idx_Guard]
    ON [lov].[Value]([RowId] ASC, [FieldId] ASC)
    INCLUDE([FieldValue]) WITH (IGNORE_DUP_KEY = ON);



